{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Connected Patterns\n",
    "\n",
    "This notebook contains the graphviz code to recrete the connected patterns diagram."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Make logos"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hit:2 http://security.debian.org stretch/updates InRelease\n",
      "Ign:3 http://deb.debian.org/debian stretch InRelease\n",
      "Hit:4 http://deb.debian.org/debian stretch-updates InRelease\n",
      "Hit:5 http://deb.debian.org/debian stretch-backports InRelease\n",
      "Hit:6 http://packages.cloud.google.com/apt gcsfuse-stretch InRelease\n",
      "Hit:7 http://deb.debian.org/debian stretch Release\n",
      "Hit:8 http://packages.cloud.google.com/apt cloud-sdk-stretch InRelease\n",
      "Hit:9 https://nvidia.github.io/libnvidia-container/stable/debian9/amd64  InRelease\n",
      "Hit:10 https://nvidia.github.io/nvidia-container-runtime/debian9/amd64  InRelease\n",
      "Hit:11 https://nvidia.github.io/nvidia-docker/debian9/amd64  InRelease\n",
      "Hit:12 https://download.docker.com/linux/debian stretch InRelease\n",
      "Hit:1 https://packages.cloud.google.com/apt kubernetes-xenial InRelease\n",
      "Hit:13 http://packages.cloud.google.com/apt google-compute-engine-stretch-stable InRelease\n",
      "Get:14 http://packages.cloud.google.com/apt google-cloud-packages-archive-keyring-stretch InRelease [3,876 B]\n",
      "Fetched 3,876 B in 1s (3,094 B/s)\n",
      "Reading package lists...\n",
      "Reading package lists...\n",
      "Building dependency tree...\n",
      "Reading state information...\n",
      "imagemagick is already the newest version (8:6.9.7.4+dfsg-11+deb9u9).\n",
      "0 upgraded, 0 newly installed, 0 to remove and 72 not upgraded.\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "sudo apt-get update -y\n",
    "sudo apt-get install -y imagemagick"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%bash\n",
    "convert -resize 10% ../mldp_cover.png logo_small.png\n",
    "convert -resize 25% ../mldp_cover.png logo_medium.png\n",
    "# convert -resize 65% ../mldp_cover.png -bordercolor green -border 5 logo_large.png\n",
    "convert -resize 180% ../mldp_cover_color.jpg -bordercolor green -border 5 logo_large.png"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%bash\n",
    "dot -Tpng connected-patterns.gv -o tmp.png\n",
    "convert tmp.png logo_small.png -gravity north -geometry +50+10 -composite connected-patterns.png\n",
    "rm tmp.png"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def display_image(filename):\n",
    "    from IPython.display import HTML, display\n",
    "    html = '<img src=\"{}\" style=\"float: left; margin-right: 10px;\" />'.format(filename)\n",
    "    print(html)\n",
    "    display(HTML(html))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<img src=\"./connected-patterns.png\" style=\"float: left; margin-right: 10px;\" />\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"./connected-patterns.png\" style=\"float: left; margin-right: 10px;\" />"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display_image('./connected-patterns.png')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## interactions diagram\n",
    "The diagram was created with XMind.  Here, we just add the logo."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%bash\n",
    "convert mldp_interactions.png logo_large.png \\\n",
    "        -gravity center -geometry +0+0 -composite \\\n",
    "        -bordercolor red -border 10 \\\n",
    "        -caption \"Machine Learning Design Patterns; by Lakshmanan, Robinson, Munn; O'Reilly 2020\" \\\n",
    "        machine-learning-design-patterns.png"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<img src=\"./machine-learning-design-patterns.png\" style=\"float: left; margin-right: 10px;\" />\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"./machine-learning-design-patterns.png\" style=\"float: left; margin-right: 10px;\" />"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display_image('./machine-learning-design-patterns.png')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Copyright 2020 Google Inc. Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License"
   ]
  }
 ],
 "metadata": {
  "environment": {
   "name": "tf2-gpu.2-1.m50",
   "type": "gcloud",
   "uri": "gcr.io/deeplearning-platform-release/tf2-gpu.2-1:m50"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
